package com.wgy.day42Jsoup;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.File;
import java.io.IOException;

/**
 * Created by pc on 2021/1/11 20:58
 * Description: LearningJava
 */
/*Element对象功能*/
public class JsoupDemo4 {
    public static void main(String[] args) throws IOException {
        //1.获取student.xml的path
        // String path = JsoupDemo3.class.getClassLoader().getResource("student.xml").getPath();
        //2.获取document对象
        Document document = Jsoup.parse(new File("student.xml"), "utf-8");
        //3.获取元素对象
        //3.1获取所有name标签对象
        Elements elements = document.getElementsByTag("name");

        Element element_student = document.getElementsByTag("student").get(0);
        Elements ele_name = element_student.getElementsByTag("name");
         //4.获取student对象的属性值
        String number = element_student.attr("number");
        System.out.println(number); //heima_0001
        String text = element_student.text();
        System.out.println(text);//tom 18 male
        String html = element_student.html();
        System.out.println(html);
/*
<name id="1">
 tom
</name>
<age>
 18
</age>
<sex>
 male
</sex>
*/

    }
}
